/**
1、即开记得型
2、双色球自选型
*/
package main

import (
	"fmt"
	"github.com/kataras/iris"
	"github.com/kataras/iris/mvc"
	"math/rand"
	"time"
)

type lotteryController struct {
	Ctx iris.Context
}

func newApp() (app *iris.Application) {
	app = iris.New()
	mvc.New(app.Party("/")).Handle(&lotteryController{})
	return
}

func main() {
	var (
		app *iris.Application
	)

	app = newApp()
	_ = app.Run(iris.Addr(":8080"))
}

// 即开记得型
func (c *lotteryController) Get() string {
	var (
		prize string
		seed  int64
		code  int
	)

	seed = time.Now().UnixNano()
	code = rand.New(rand.NewSource(seed)).Intn(10) + 1
	switch code {
	case 1:
		prize = "一等奖"

	case 2 | 3:
		prize = "二等奖"
	case 4 | 5 | 6:
		prize = "三等奖"
	default:
		return fmt.Sprintf("尾号为1获得一等奖<br>尾号为2或者3获得三等奖<br>尾号为4、5、6获得三等奖<br>code=%d<br>很遗憾，没有获奖", code)
	}
	return fmt.Sprintf("尾号为1获得一等奖<br>尾号为2或者3获得三等奖<br>尾号为4、5、6获得三等奖<br>code=%d<br>恭喜你，获得：%s", code, prize)
}

// 双色球自选型
func (c *lotteryController) GetPrize() string {

	var (
		prize [7]int
		i     int
	)

	seed := time.Now().UnixNano()

	r := rand.New(rand.NewSource(seed))

	// 前6个红色球1-33
	for i = 0; i < 6; i++ {
		prize[i] = r.Intn(33)
	}

	// 最后一位的蓝色球 1-16
	prize[6] = r.Intn(16) + 1

	return fmt.Sprintf("今日开奖号码是：%v", prize)
}
